package oj;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-4-25 17:07
 * @description：
 * @modified By：
 * @version:
 */
public class Oj10 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] list = new int[size];
            for (int i = 0; i < size; i++) {
                list[i]  = in.nextInt();
            }
            Arrays.sort(list);//升序
            int min = 0;
            ArrayList<Integer> arrayList = new ArrayList<>();
            for (int i = 0; i < list.length; i++) {
                arrayList.add(list[i]);
            }

            for (int i = arrayList.size()-1; i >0;i = arrayList.size()-1) {
                Integer a = arrayList.get(i);
                Integer b = arrayList.get(i - 1);
                min+=a*b;
                arrayList.remove(i);
                arrayList.remove(i-1);
                arrayList.add(a+b);
            }
            System.out.println(min);
        }
    }
}
